/*
 * InvitationManagerBean.java
 *
 * Created on September 19, 2007, 12:12 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package timeitj.ejb.invitation;

import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.NoResultException;
import org.apache.log4j.Logger;
import timeitj.ejb.persistence.PersistenceManagerAbstract;
import timeitj.persistence.Invitation;
import timeitj.persistence.Person;
import timeitj.persistence.Project;

/**
 *
 * @author wallner
 */
@Stateless
public class InvitationManagerBean extends PersistenceManagerAbstract<Invitation, Long> 
    implements InvitationManager {
    
    
    /** Creates a new instance of InvitationManagerBean */
    public InvitationManagerBean() {
        log = Logger.getLogger(InvitationManagerBean.class.getName());
        log.debug("InvitationManagerBean instantiated");
    }
    
    public List<Invitation> getInvitationsByInviter(Person inviter){
        List<Invitation> invitations;
        try {
            invitations = 
                (ArrayList<Invitation>) em.createNamedQuery("getInvitationsByInviter")
                    .setParameter("inviter", inviter)
                    .getResultList();
        } catch (NoResultException ex){
            return null;
        }
        return invitations;
    }
    
    public List<Invitation> getInvitationsByProject(Project project){
        List<Invitation> invitations;
        try {
            invitations = 
                (ArrayList<Invitation>) em.createNamedQuery("getInvitationsByProject")
                    .setParameter("project", project)
                    .getResultList();
        } catch (NoResultException ex){
            return null;
        }
        return invitations;
    }
    
    public List<Invitation> getInvitationsForInvitee(Person invitee) {
        List<Invitation> invitations;
        try {
            invitations = 
                (ArrayList<Invitation>) em.createNamedQuery("getInvitationForInvitee")
                    .setParameter("invitee", invitee)
                    .getResultList();
        } catch (NoResultException ex){
            return null;
        }
        return invitations;
    }
}
